
package com.hlkj.pay.controller.common;

import cn.hutool.core.bean.BeanUtil;
import com.hlkj.framework.common.pojo.CommonResult;
import com.hlkj.framework.common.pojo.LocalContext;
import com.hlkj.framework.common.pojo.PageResult;
import com.hlkj.framework.common.util.collection.CollectionUtils;
import com.hlkj.pay.controller.BaseController;
import com.hlkj.pay.dto.common.ExportRecordQueryDto;
import com.hlkj.pay.infrastructure.model.common.ExportRecordDO;
import com.hlkj.pay.service.common.IExportRecordService;
import com.hlkj.pay.vo.common.req.ExportRecordPageQueryReq;
import com.hlkj.pay.vo.common.resp.ExportRecordResp;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Collections;
import java.util.List;

@Tag(name = "导出记录")
@RestController
@RequestMapping("/v1/common/export")
@RequiredArgsConstructor
@Slf4j
public class ExportRecordController extends BaseController {

    private final IExportRecordService exportRecordService;

    @Operation(summary = "导出列表")
    @GetMapping("/page")
    CommonResult<PageResult<ExportRecordResp>> queryTemplatePage(@Validated ExportRecordPageQueryReq pageParam) {
        ExportRecordQueryDto queryDO = BeanUtil.copyProperties(pageParam, ExportRecordQueryDto.class);
        PageResult<ExportRecordDO> pageResult = exportRecordService.queryPage(queryDO);
        List<ExportRecordDO> list = pageResult.getList();
        if (CollectionUtils.isEmpty(list)) {
            return buildPageResult(pageResult, Collections.emptyList());
        }
        List<ExportRecordResp> templateResps = BeanUtil.copyToList(list, ExportRecordResp.class);
        return buildPageResult(pageResult, templateResps);
    };

}
